﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Yugi_Gui.COntrol
{
    /// <summary>
    /// Interaction logic for SmallImg.xaml
    /// </summary>
    public partial class SmallImg : UserControl
    {
        public TypePRS type;
        
        public int index;
        public Action<SmallImg> ClickImage;
        public SmallImg( TypePRS t, int i)
        {
            InitializeComponent();
            type = t;
            
            index = i;
            LoadImage();
            img.MouseEnter += new MouseEventHandler(img_MouseEnter);
            img.MouseLeave += new MouseEventHandler(img_MouseLeave);
            img.MouseLeftButtonDown += new MouseButtonEventHandler(img_MouseLeftButtonDown);
        }

        public void NormalState()
        {
            img_MouseLeave(null, null);
        }

        public void HighlightState()
        {
            img_MouseEnter(null, null);
        }

        public void LostMouse()
        {
            img.MouseEnter -= new MouseEventHandler(img_MouseEnter);
            img.MouseLeave -= new MouseEventHandler(img_MouseLeave);
        }

        public void GotMouse()
        {
            img.MouseEnter += new MouseEventHandler(img_MouseEnter);
            img.MouseLeave += new MouseEventHandler(img_MouseLeave);
        }

        void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            StackPanel stack = (StackPanel)this.Parent;
            //Storyboard sb = (Storyboard)Application.Current.FindResource("Storyboard1");
            //Storyboard sb =(Storyboard)win.FindResource("Storyboard1");
            //MessageBox.Show(sb.ToString());

            //for (int i = 0; i < 20; i++)
            //{
            //    SmallImg im = (SmallImg)win.stackPanel1.Children[i];         
            //}


            ClickImage(this);
        }

        private void LoadImage()
        {
            switch (type)
            {
                case TypePRS.Paper:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/p1.jpg"));
                    break;
                case TypePRS.Rock:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/r1.jpg"));
                    break;
                case TypePRS.Scissors:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/s1.jpg"));
                    break;
                case TypePRS.Unknown:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/o1.jpg"));
                    break;
            }
        }

        void img_MouseLeave(object sender, MouseEventArgs e)
        {
            switch (type)
            {
                case TypePRS.Paper:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/p1.jpg"));
                    break;
                case TypePRS.Rock:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/r1.jpg"));
                    break;
                case TypePRS.Scissors:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/s1.jpg"));
                    break;
            }

        }

        void img_MouseEnter(object sender, MouseEventArgs e)
        {
            switch (type)
            {
                case TypePRS.Paper:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/p2.jpg"));
                    break;
                case TypePRS.Rock:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/r2.jpg"));
                    break;
                case TypePRS.Scissors:
                    img.Source = new BitmapImage(new Uri("pack://application:,,,/Image/RPG/s2.jpg"));
                    break;
            }
        }
    }
    public enum TypePRS
    {
        Rock,
        Paper,
        Scissors,
        Unknown
    }
}
